package com.shopping.orm;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class CommodityDescDao extends HibernateDaoSupport {

	private static final Log log = LogFactory.getLog(CommodityDescDao.class);
	public void save(Factory instance){
		log.debug("saving CommodityDesc instance");
		try{
		getHibernateTemplate().save(instance);
		log.debug("save CommodityDesc successful");
		}catch(RuntimeException re){
			log.error("save CommodityDesc failed",re);
			throw re;
		}
	}
	
	public void delete(CommodityDesc instance) {
        log.debug("deleting CommodityDesc instance");
        try {
            getHibernateTemplate().delete(instance);
            log.debug("delete CommodityDesc instance successful");
        } catch (RuntimeException re) {
            log.error("delete CommodityDesc instance failed", re);
            throw re;
        }
    }
	
	public void update(CommodityDesc instance){
		log.debug("Upate CommodityDesc instance");
		try{
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("update CommodityDesc instance  successful");
			
		}catch(RuntimeException re){
			log.error("update CommodityDesc instance failed",re);
			throw re;
		}
	}
	public List findByExample(CommodityDesc instance){
		log.debug("get CommodityDesc instance with +:example");
		try{
			List result = getHibernateTemplate().findByExample(instance);
			log.debug("get successful!");
			return result;
		}catch(RuntimeException re){
			log.error("get failed",re);
			throw re;
		}
	}
	
	public List findByproperty(String propertyName,Object value){
		log.debug("finding CommodityDesc instance with property:"+ propertyName + ",value:"+value);
		try {
		    String queryString = "from CommodityDesc as model where model." 
		         						+ propertyName + "= ?";
		    return getHibernateTemplate().find(queryString, value);
		}catch(RuntimeException re){
			log.error("find by property failed",re);
			throw re;
		}
	}
	
	
	public List findAll(){
		log.debug("getting CommodityDesc instance");		
		try{
			List result = getHibernateTemplate().findByExample("CommodityDesc");
			log.debug("find successful!");
			return result;
		}catch(RuntimeException re){
			log.error("get failed",re);
			throw re;
		}
	}
	
	
	public CommodityDesc findById(String uid){
		log.debug("get CommodityDesc instance with id:+uid");
		try{
			CommodityDesc instance = (CommodityDesc)getHibernateTemplate().get("CommodityDesc", uid);
			log.debug("get successful!");
			return instance;
		}catch(RuntimeException re){
			log.error("get failed",re);
			throw re;
		}	
	}
}
